package org.example.mybattis.mapper;


import org.apache.catalina.User;
import org.apache.ibatis.annotations.*;
import org.example.mybattis.model.UserInfo;

import java.util.List;

@Mapper
public interface  UserInfoMapper {

    @ResultMap("resultMap")
    @Select("select * from userinfo")
    List<UserInfo> getUserInfoAll();

    @Select("select * from userinfo where delete_flag = #{flag} and gender = #{gender}")
    List<UserInfo> getUserByDelete(@Param("flag") Integer deleteFlag, Integer gender);

    //使用#号
    @Select("select * from userinfo where delete_flag = #{deleteFlag}")
    List<UserInfo> getUserInfoByDeleteFlag(Integer deleteFlag);


    //使用￥号
    @Select("select * from userinfo where delete_flag = ${deleteFlag}")
    List<UserInfo> getUserInfoByDeleteFlag2(Integer deleteFlag);




    @Options(useGeneratedKeys = true,keyProperty =  "id")
    @Insert("insert into userinfo (username, password, age, gender) values (#{username}, #{password}, #{age}, #{gender})")
    Integer insert(UserInfo userInfo);

    //删除操作：
    @Delete("delete from userinfo where id = #{id}")
    Integer delete(Integer id);


    //更新操作
    @Update("update userinfo set password = #{password}, age = #{age}, gender = #{gender} where id= #{id}")
    void update(UserInfo userInfo);


    /*
    指定结果映射关系：
     */
    @Results(id = "resultMap", value = {
            @Result(column = "delete_flag", property = "deleteFlag"),
            @Result(column = "create_time", property = "createTime"),
            @Result(column = "update_time", property = "updateTime")
    })
    @Select("select * from userInfo")
    List<UserInfo> selectInfos4();


    /*
    驼峰自动转换：
     */

    @Select("select * from userinfo")
    List<UserInfo> selectUserInfo5();


    @Select("select * from userinfo where username = #{username}")
    UserInfo getUserByName(String userName);

    @Select("select * from userinfo where username = ${username}")
    UserInfo getUserByName2(String userName);


    @Select("select * from userinfo where username like '%${username}%'")
    List<UserInfo> UserLike(String username);

    @Insert("insert into ")
    Integer insertByCondtion(UserInfo userInfo);
}
